﻿using Helpers.Common;
using log4net;
using log4net.Config;
using System;
using System.IO;

namespace Helpers.Log
{
    /// <summary>
    /// A wrapper of the <typeparamref name="log4net.ILog"/> class. to add the functionality of ignore some repeated log events
    /// on a certain interval of time.
    /// </summary>
    public static class Logger
    {
        #region Static Properties

        /// <summary>
        /// Indicates if the log4net configuration was set.
        /// </summary>
        private static bool configured = false;

        #endregion

        #region Static Methods

        /// <summary>
        /// Gets the logger configured on the config file.
        /// </summary>
        /// <param name="loggerName">The logger name to obtain.</param>
        /// <returns></returns>
        public static ILog GetLogger(string loggerName)
        {
            if (Logger.configured == false)
            {
                string configFile = HelperCommon.GetExecutingExePath() + AppDomain.CurrentDomain.FriendlyName + ".config";

                XmlConfigurator.ConfigureAndWatch(new FileInfo(configFile));

                Logger.configured = true;
            }

            return LogManager.GetLogger(loggerName);
        }
        public static void ConfirmConfiguration()
        {
            Logger.configured = true;
        }

        #endregion
    }
}